package com.q.controller;


import com.q.bean.User;
import com.q.dao.UserDao;
import com.q.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ShowUserServlet",urlPatterns = "/Show")
public class ShowUserServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String page = req.getParameter("page");
        int pageInt = Integer.parseInt(page);
        String limit = req.getParameter("limit");
        int limitInt = Integer.parseInt(limit);
        int pageNum = (pageInt-1)*limitInt;
        UserDao userDao =new UserDaoImpl();
        List<User> users=null;

        try {
            users = userDao.ShowUser(pageNum,limitInt);
        } catch (Exception e) {
            e.printStackTrace();
        }
            req.getSession().setAttribute("use",users);
            req.getRequestDispatcher("ShowUser.jsp").forward(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
